#include "SqList.h"

int compareSame(ElemType e,ElemType f);
void visit(ElemType e);
int compareDifference(ElemType e,ElemType f);

int main() {
    SqList L;
    InitList_Sq(&L);

    for (int i = 0; i < 5; ++i) {
        //顺序线性表尾插
        ListPushBack_Sq(&L,i+1);
    }
    //遍历线性表
    ListTraverse_Sq(&L,visit);
    printf("\n");

    //线性表插入
//    ListInsert_Sq(&L,3,10);
//    ListInsert_Sq(&L,1,10);
//    ListInsert_Sq(&L,0,10);
//    ListInsert_Sq(&L,5,10);
//    ListInsert_Sq(&L,6,10);
//    ListInsert_Sq(&L,99,10);

    //线性表删除
//    printf("delete:%d\n",ListDelete_Sq(&L,3));
//    printf("delete:%d\n",ListDelete_Sq(&L,0));
//    printf("delete:%d\n",ListDelete_Sq(&L,5));
//    printf("delete:%d\n",ListDelete_Sq(&L,6));

    //获取元素e所在位置
//    printf("Num:%d\tLocate:%d\n",0, LocateElem_Sq(&L,0,compareSame));
//    printf("Num:%d\tLocate:%d\n",1, LocateElem_Sq(&L,1,compareSame));
//    printf("Num:%d\tLocate:%d\n",2, LocateElem_Sq(&L,2,compareSame));

//    printf("Num:%d\tLocate:%d\n",3, LocateElem_Sq(&L,3,compareSame));
//    printf("Num:%d\tLocate:%d\n",4, LocateElem_Sq(&L,4,compareSame));
//    printf("Num:%d\tLocate:%d\n",5, LocateElem_Sq(&L,5,compareSame));
//    printf("Num:%d\tLocate:%d\n",6, LocateElem_Sq(&L,6,compareSame));

    //将两个顺序线性表合并
//    SqList L2;
//    InitList_Sq(&L2);
//    for (int i = 0; i < 10; ++i) {
//        ListPushBack_Sq(&L2,i+10);
//    }
//
//    SqList Lc;
//    MergeList_Sq(&L,L2,&Lc,compareDifference);

    //将顺线性表置空
//    ClearList_Sq(&L);

    //销毁线性表
//    DestroyList_Sq(&L);

    //获取线性表中第i个元素
//    for (int i=1;i<=5;i++){
//        printf("Elem:%d\n", GetElem_Sq(&L,i));
//    }

    //获取元素e前的元素
//    for (int i = 0; i <= 6; ++i) {
//        printf("Elem:%d\tPreElem:%d\n",i, PriorElem_Sq(&L,i,compareSame));
//    }

    //获取元素e后的元素
//    for (int i = 0; i <= 6; ++i) {
//        printf("Elem:%d\tPostElem:%d\n",i, NextElem_Sq(&L,i,compareSame));
//    }

    //遍历线性表
    ListTraverse_Sq(&L,visit);

    return 0;
}

void visit(ElemType e){
    printf("%d\t",e);
}

int compareSame(ElemType e,ElemType f){
    if(e==f)    return TRUE;
    else    return FALSE;
}

int compareDifference(ElemType e,ElemType f){
    if(e<=f)    return TRUE;
    else    return FALSE;
}
